package com.tmsb.utils;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;

import java.util.Properties;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/6/24 16:20
 */
public class ConfUtil {
    /**
     * 全局配置文件
     */
    private  static Config appConfig = ConfigService.getAppConfig();

    public static int getCheckpointInterval(){
        return appConfig.getIntProperty("checkpoint.interval",60000);
    }
    public static String getCheckpointUri(){
        return appConfig.getProperty("checkpoint.uri","hdfs://nameservice1:8020/user/flink/checkpoints");
    }
    public static int getCheckpointMinPauseBetween(){
        return appConfig.getIntProperty("checkpoint.min.pause.between",10000);
    }
    public static int getParallelism(){
        return appConfig.getIntProperty("parallelism",1);
    }
    public static String getBootstrapServers(){
        return appConfig.getProperty("kafka.bootstrap.servers","116.62.114.253:9092,47.98.43.253:9092,47.98.48.2:9092");
    }
    public static String getGroupId(){
        return appConfig.getProperty("kafka.group.id","cg-flink");
    }
    public static String getOffsetReset(){
        return appConfig.getProperty("kafka.auto.offset.reset","latest");
    }
    public static String getRedisCluster(){
        return appConfig.getProperty("redis.cluster","172.16.9.14:8001,172.16.9.14:8002,172.16.9.15:8001,172.16.9.15:8002,172.16.9.16:8001,172.16.9.16:8002,172.16.9.18:8001,172.16.9.18:8002,172.16.9.19:8001,172.16.9.19:8002");
    }
    public static String getRedisPwd(){
        return appConfig.getProperty("redis.pwd","tmsb@bigdata2020");
    }
    public static Integer getRedisTtlDay(){
        return appConfig.getIntProperty("redis.ttl.day",-2);
    }
    //redis del keys
    public static String[] getDelRedisKeys() {
        String keys = appConfig.getProperty("del.redis.keys", "test");
        return keys.split(",");
    }

    public static String getSumNumRedisPreKey(){
        return appConfig.getProperty("pre.sum.num","order:num:");
    }
    public static String getSumMoneyRedisPreKey(){
        return appConfig.getProperty("pre.sum.money","order:money:");
    }
    public static String getTopGoodsRedisPreKey(){
        return appConfig.getProperty("top.goods","top:goods:");
    }
    public static String getTopSellerRedisPreKey(){
        return appConfig.getProperty("top.seller","top:sellers:");
    }
    public static String getTopicOfMall(){
        return appConfig.getProperty("topic.mall","MYSQL_MALL");
    }
    public static int getTriggerInterval(){
        return appConfig.getIntProperty("trigger.interval.second",10);
    }
    public static String getShopTypePreKey(){
        return appConfig.getProperty("shop.type.sum","shop.type.sum");
    }


    //ucenter DAU
    public static String getTopicOfUcenter(){ return appConfig.getProperty("topic.ucenter","MYSQL_UCENTER"); }
    public static Integer getfailureRate(){ return appConfig.getIntProperty("failure.rate",3); } //每个时间间隔的最大故障次数
    public static Integer getfailureInterval(){ return appConfig.getIntProperty("failure.interval",5); } //固定时间间隔,单位 分钟
    public static Integer getdelayInterval(){ return appConfig.getIntProperty("delay.interval",10); } //两次重启的延迟时间,单位 秒
    public static String getDauCheckpointUri(){ return appConfig.getProperty("dau.checkpoint.uri","hdfs://nameservice1:8020/user/flink/checkpoints/DailyActivateUnits"); }
    public static String getDauRedisKey(){return appConfig.getProperty("ucenter.user.dau","ucenter:dau");}
    public static String getProvincesDauRedisKey(){return appConfig.getProperty("ucenter.user.provinces.dau","ucenter:provinces:dau:");}
    public static String getDayRegistRedisKey() {
        return appConfig.getProperty("ucenter.user.day.register","ucenter:day:register");
    }
    public static String getDayProvinceRegistRedisKey() {
        return appConfig.getProperty("ucenter.user.day.province.register","ucenter:day:provinces:register:");
    }

    public static int getMaxTotal() {
        return appConfig.getIntProperty("redis.max.total",50);
    }
    public static int getMaxIdle() {
        return appConfig.getIntProperty("redis.max.idle",10);
    }
    public static int getMinIdle() {
        return appConfig.getIntProperty("redis.min.idle",0);
    }
    public static long MaxWaitMillis() {
        return appConfig.getIntProperty("redis.max.waitmillis",5000);
    }


    //ES Score
    public static String getTopicOfScore(){ return appConfig.getProperty("topic.score","ES_SCORE"); }
    public static String getScoreAnalysisCheckpointUri(){ return appConfig.getProperty("es.score.analysis.uri","hdfs://nameservice1:8020/user/flink/checkpoints/ScoreAnalysis"); }
    public static String getScoreAmountRedisKey() {
        return appConfig.getProperty("es.score.amount","es:score:amount");
    }
    public static String getScoreCityAmountRedisKey() {
        return appConfig.getProperty("es.score.city.amount","es:score:city:amount:");
    }

    //taimu_main user_stock_buy
    public static String getTopicOfTaiMuMain(){ return appConfig.getProperty("topic.taimu_main","MYSQL_TAIMU_MAIN"); }
    public static String getUserStockBuyCheckpointUri(){ return appConfig.getProperty("taimu_main.user_stock_buy.uri","hdfs://nameservice1:8020/user/flink/checkpoints/UserStockBuy"); }
    public static String getUserStockBuyAmountRedisKey() {
        return appConfig.getProperty("taimu_main.user_stock_buy.amount","taimu_main:user_stock_buy:amount");
    }
    public static String getUserStockBuyDiscountRedisKey() {
        return appConfig.getProperty("taimu_main.user_stock_buy.discount","taimu_main:user_stock_buy:discount");
    }


    ////taimu_main user_tixian
    public static String getUserTiXianAmountRedisKey() {
        return appConfig.getProperty("taimu_main.user_tixian.amount","taimu_main:user_tixian:amount");
    }


    public static String getUserTiXianFeeRedisKey() {
        return appConfig.getProperty("taimu_main.user_tixian.fee","taimu_main:user_tixian:fee");
    }


    //tmsb_fair_shop
    public static String getTopicOfFairShop(){ return appConfig.getProperty("topic.fair_shop","MYSQL_FAIR_SHOP"); }
    public static String getOrderNetworkQuantityRedisKey(){return appConfig.getProperty("fair_shop.order_network.quantity","fair_shop:order_network:quantity");}
    public static String getOrderVerifyQtyRedisKey(){return appConfig.getProperty("fair_shop.order_verified_network.verify_qty","fair_shop:order_verified_network:verify_qty");}
    public static String getOrderMallRedisKey(){return appConfig.getProperty("fair_shop.order_mall.sku_quantity","fair_shop:order_mall:sku_quantity");}
    public static String getFairShopAnalysisCheckpointUri(){ return appConfig.getProperty("fair_shop.fair_shop_analysis.uri","hdfs://nameservice1:8020/user/flink/checkpoints/FairShopAnalysis"); }

    //TODO ES Alarm
    public static String getTopicOfAvailable(){ return appConfig.getProperty("topic.available","ES_STOCK_AVAILABLE"); }
    public static String getStockAvaAlarmCheckpointUri(){ return appConfig.getProperty("es_available_alarm.checkpoint.uri","hdfs://nameservice1:8020/user/flink/checkpoints/StockAvailableAnalysis"); }
    public static String getMallStockAlarmCheckpointUri(){ return appConfig.getProperty("es_mall_alarm.checkpoint.uri","hdfs://nameservice1:8020/user/flink/checkpoints/MallStockAnalysis"); }
    public static String getStockLockAlarmCheckpointUri(){ return appConfig.getProperty("es_lock_alarm.checkpoint.uri","hdfs://nameservice1:8020/user/flink/checkpoints/StockLockAnalysis"); }
    public static String getStockPenAlarmCheckpointUri(){ return appConfig.getProperty("es_pension_alarm.checkpoint.uri","hdfs://nameservice1:8020/user/flink/checkpoints/StockPensionAnalysis"); }
    public static String getTopicOfPension(){ return appConfig.getProperty("topic.pension","ES_STOCK_PENSION"); }
    public static String getTopicOfLock(){ return appConfig.getProperty("topic.lock","ES_STOCK_LOCK"); }
    public static String getTopicOfMallStock(){ return appConfig.getProperty("topic.mallstock","ES_MALL_STOCK"); }
    //TODO  kafka配置
    public static Properties getKafkaProperties(){
        //TODO source
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers",ConfUtil.getBootstrapServers());
        properties.setProperty("group.id", ConfUtil.getGroupId());
 //       properties.setProperty("group.id", "TEST");
        properties.setProperty("key.deserializer",
                "org.apache.kafka.common.serialization.StringDeserializer");
        properties.setProperty("value.deserializer",
                "org.apache.kafka.common.serialization.StringDeserializer");
        properties.setProperty("auto.offset.reset", ConfUtil.getOffsetReset()); // earliest latest
        return  properties;
    }
}
